//封装axios的文件
import axios from 'axios'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
const servise = axios.create({
    baseURL: '/mock',
    timeout: 20000,
    // headers: {'X-Custom-Header': 'foobar'}
  });
  //请求拦截器
  servise.interceptors.request.use(function (config) {
    // Do something before request is sent
    Nprogress.start()//开启进度条
    return config;
  },
  //响应拦截器
  servise.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    Nprogress.done()
    return response.data;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    alert('错误信息为:'+error.message)
    Nprogress.done()
    // return Promise.reject(error);//可以选择处理错误或中断promise链
    return new Promise(() => {})//pending状态中断链
  }));
  export default servise
